package {{configPack}};

import java.sql.SQLException;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;


import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.pool.DruidDataSource;
import com.google.common.collect.Lists;
import {{pack}}.utils.RestService;


@Configuration
public class DbConfig {

  @ConfigurationProperties(prefix="spring.druid")
  @Bean(initMethod="init",destroyMethod="close")
  public DruidDataSource dataSource(Filter statFilter) throws SQLException{
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setProxyFilters(Lists.newArrayList(statFilter));
    return dataSource;
  }

  @Bean
  public Filter statFilter(){
    StatFilter filter = new StatFilter();
    filter.setSlowSqlMillis(5000);
    filter.setLogSlowSql(true);
    filter.setMergeSql(true);
    return filter;
  }

  @Bean
  public RestService restService(RestTemplate restTemplate){
     RestService restService = new RestService();
     restService.setRestTemplate(restTemplate);
     return restService;
  }

}
